package com.atwisdom.star.service.util;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.atwisdom.star.exception.pojo.BusinessException;

/**
 * @author Panhao
 * @ClassName Validate
 * @description TODO
 * @date 2024/4/15
 * lastUpdate Panhao
 */
public class ValidateUtil {

    /**
     * String null,undified,"","   " 都是空
     * map null,undified,{} 都是空
     * [] null,undified,length == 0 是空
     * 判断参数对象是否为空
     * @param obj
     * @return
     */
    public static Boolean hasEmpty(Object ...obj){
        if(!ObjectUtil.isAllNotEmpty(obj)){
            new BusinessException("500","参数不能为空");
        }
        return ObjectUtil.isEmpty(obj);
    }

    /**
     * 判断参数对象是否为空
     * @param obj
     * @return
     */
    public static Boolean isEmpty(Object obj,String key){
        if(ObjectUtil.isEmpty(obj)){
            throw new BusinessException("500",key+"参数不能为空");
        }
        return ObjectUtil.isEmpty(obj);
    }
    /**
     * 判断参数是否为空,不为空返回数据
     * @param str
     * @return
     */
    public static String validateEmpty(String str,String key){
        if(StrUtil.isEmpty(str)){
           throw new BusinessException("500",key+"参数不能为空");
        }
        return str;
    }

    /**
     * 判断参数是否为空,不为空返回数据
     * @param integer
     * @return
     */
    public static Integer validateEmpty(Integer integer,String key){
        if(ObjectUtil.isEmpty(integer)){
            throw new BusinessException("500",key+"参数不能为空");
        }
        return integer;
    }
}
